from appium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
import os,time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class Base2():
    def __init__(self):
        os.system('adb shell')
        cap = {
            "platformName": "Android",
            "deviceName": "emulator-5554",
            "noReset": True,
            "appPackage": "com.kongfz.app",
            "appActivity": "com.kongfz.app.home.mvvm.homepage.HomeActivity"
        }
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        self.driver.implicitly_wait(25)
        sleep(15)

    def find_ele(self,loc):
        if type(loc) == str:
            return self.driver.find_element_by_android_uiautomator(loc)
        else:
            return self.driver.find_element(*loc)
    def find_ele_wait(self,loc):
        return WebDriverWait(self.driver,500).until(EC.presence_of_element_located(loc))

    def find_key_values(self,loc,key):
        ele = self.find_ele(loc)
        return ele.get_attribute(key)
    def jieping(self,filename):
        t = self.driver.find_element_by_android_uiautomator()
        return t.get_attribute(filename)

    def tuichu(self):
        self.driver.quit()